package cn.algorithm;

import java.time.Instant;
import java.util.HashMap;

/**
 * @author: lizemin
 * @version: 1.0
 */
public class Test {

    public static int fib(int n) {
        if (n == 1){
            return 1;
        }
        if (n == 0){
            return 0;
        }
        return fib(n - 1) + fib(n - 2);

    }

    public static int fib2(int n) {
        if (n < 2) {
            return n;
        }
        int p = 0, q = 0, r = 1;
        for (int i = 2; i <= n; ++i) {
            // f(1) +
            p = q;
            q = r;
            r = p + q;
        }
        return r;//
    }

    //这是一个main方法,是程序的入口
    public static void main(String[] args) {
        int fib = fib2(5);
        System.out.println(fib);

    }


}
